import { reqDetailInfo, reqGoodsCarInfo } from "@/api";
import { getUUID } from '@/utils/uuid_token';

export default {
    state: {
        goodsDetailList: {},
        uuid_token: getUUID(),
    },
    actions: {
        //获取详情信息
        async getGoodsDetail({ commit }, skuId) {
            let result = await reqDetailInfo(skuId);
            if (result.code === 200) {
                commit('GETGOODSDETAIL', result.data);
            }
        },
        //将商品加入购物车
        async getGoodsCarList({ commit }, { skuId, skuNum }) {
            let result = await reqGoodsCarInfo(skuId, skuNum);
            if (result.code === 200) {
                return 'ok';
            } else {
                return Promise.reject(new Error('faile'));
            }
        }
    },
    mutations: {
        GETGOODSDETAIL(state, goodsDetailList) {
            state.goodsDetailList = goodsDetailList;
        }
    },
    getters: {
        categoryView({ goodsDetailList: { categoryView } }) {
            return categoryView || {};
        },
        skuInfo({ goodsDetailList: { skuInfo } }) {
            return skuInfo || {};
        },
        //商品属性值
        spuSaleAttrList({ goodsDetailList: { spuSaleAttrList } }) {
            return spuSaleAttrList || [];
        }
    }

}